#include "sendfilewidget.h"

SendFileWidget::SendFileWidget(const QString &str1, const QString &str2, qint64 total, QWidget *parent)
    : QWidget(parent), mProgressBar(new QProgressBar), mLabelBytes(new QLabel), mValTotal(total), mStrTotal(GetFileSize(total))
{
    mLabelMsg = new QLabel(str1);
    mLabelMsg->setStyleSheet("color:rgb(0,0,255)");
    QLabel *label = new QLabel(str2);
    label->setMinimumWidth(14);
    mProgressBar->setMaximum(128);
    mProgressBar->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);

    QHBoxLayout *layTop = new QHBoxLayout;
    layTop->addWidget(mLabelMsg);
    layTop->addWidget(label);
    layTop->addStretch();
    layTop->addWidget(mLabelBytes);

    QVBoxLayout *layMain = new QVBoxLayout;
    layMain->addLayout(layTop);
    layMain->addWidget(mProgressBar);
    setLayout(layMain);

    setProgress(0);
}

void SendFileWidget::setMsg(const QString &str) {
    mLabelMsg->setText(str);
}
void SendFileWidget::setProgressBarVisible(bool visible) {
    mProgressBar->setVisible(visible);
}
void SendFileWidget::setProgress(qint64 value) {
    mProgressBar->setValue((int)(128 * value / mValTotal));
    mLabelBytes->setText(GetFileSize(value) + '/' + mStrTotal);
    mProgress = value;
}
